package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysAnnouncement;
import com.hl.sfzy.mapper.SysAnnouncementMapper;
import com.hl.sfzy.service.SysAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Transient;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysAnnouncementServiceImpl
 * @date 2024/7/11 20:03
 */

@Service
public class SysAnnouncementServiceImpl implements SysAnnouncementService {

    @Autowired
    private SysAnnouncementMapper sysAnnouncementMapper;


    @Override
    public int add(SysAnnouncement entity) {
        return sysAnnouncementMapper.insert(entity);
    }

    @Override
    public int edit(SysAnnouncement entity) {
        return sysAnnouncementMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return sysAnnouncementMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysAnnouncementMapper.deleteBatch(ids);
    }

    @Override
    public List<SysAnnouncement> find(SysAnnouncement entity) {
        return sysAnnouncementMapper.select(entity);
    }

    @Override
    public SysAnnouncement findById(Integer id) {
        return sysAnnouncementMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysAnnouncement entity) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysAnnouncement> list = sysAnnouncementMapper.select(entity);
        PageInfo<SysAnnouncement> pageInfo = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());
        return map;
    }
}
